package service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import dao.RecordDAO;
import entity.Category;
import entity.Record;
import gui.panel.CategoryPanel;
import gui.panel.CheckCenterPanel;
import gui.panel.SearchPanel;
 
public class CheckService {
    public int getnum() {
 
    int num=CheckCenterPanel.instance.getSelectedInteger();
    return num;
    }
    int num=CheckCenterPanel.instance.getSelectedInteger();
    public List<Record> rlist=new ArrayList<>();
    Category c=new Category();
    CheckCenterPanel p=CheckCenterPanel.instance;
    public CheckService() {
        CategoryPanel cp=CategoryPanel.instance;
        // TODO Auto-generated method stub
        c=cp.getSelectedCategory();
        rlist=new RecordDAO().list(c.id);
          
    }
    public List<Integer> rlist(){
        CategoryPanel cp=CategoryPanel.instance;
         
        c=cp.getSelectedCategory();
        List<Record> rl=new ArrayList<>();
        rl=new RecordDAO().list(c.id);
        List<Integer> number=new ArrayList<>();
       
         
        for(int i=0;i<rl.size();i++) {
            number.add(i);
        }
        return number;
         
    }
    public void update(int spend,String comment,Date date) {
         
    Record record=rlist.get(num);
   
    record.spend=spend;
    record.comment=comment;
    record.date=date;
    new RecordDAO().update(record);
    rlist=new RecordDAO().list(c.id);
      
    }
     
    public Record list(){
        Record r=rlist.get(num);
        return r;
    }
}
